import { NoSkinCellRenderer } from "../common/item/NoSkinCellRenderer";
import { ObjCreate } from "../common/ObjCreate";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { Language } from "../../../../extend/language/Language";
import { ImagesConst } from "../../resource/ImagesConst";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { MsgManager } from "../../manager/MsgManager";
import { TaskInfo } from "../../model/TaskInfo";
import { TaskDesInfo } from "../../model/task/TaskDesInfo";
import { ColorConfig } from "../../resource/ColorConfig";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { TaskConfig } from "../../resource/TaskConfig";
import { ETaskStatus } from "../../../../Message/Game/ETaskStatus";
import { ObjectPool } from "../../../../com/gengine/utils/pools/ObjectPool";
import { BaseItemNormal } from "../common/item/BaseItemNormal";
import { ItemData } from "../../resource/info/ItemData";
import { EReward } from "../../../../Message/Public/EReward";
import { GButton } from "../../../../com/mui/controls/GButton";
import { _taskInfo } from "../../../../this/_taskInfo";
//class TaskListCellRender
    
    export  class TaskListCellRender extends NoSkinCellRenderer
    {
        constructor()
        {
            super();
            return;
        }

        protected /* override */ createChildren(): void
        {
            this._rewardsBox = new Object /* flash.display.Sprite */();
            ObjCreate.setObjAttri(this._rewardsBox, 265, 6, -1, -1, this);
            var loc1=GlobalStyle.textFormat6;
            loc1.align = flash.text.TextFormatAlign.CENTER;
            this._taskName = ObjCreate.createTextField("", 0, 13, 112, 17, this, loc1);
            loc1 = GlobalStyle.textFormat1;
            loc1.align = flash.text.TextFormatAlign.CENTER;
            loc1.leading = 5;
            this._taskContent = ObjCreate.createTextField("", 97, 2, 196, 17, this, loc1);
            this._taskContent.autoSize = flash.text.TextFieldAutoSize.CENTER;
            var loc2;
            this._taskContent.wordWrap = loc2 = true;
            this._taskContent.multiline = loc2;
            this._taskContent.mouseWheelEnabled = false;
            this._taskContent.addEventListener(flash.events.TextEvent.LINK, this.onTextLinkHandler);
            this._experice = ObjCreate.createTextField("", 457, 6, 95, 17, this, GlobalStyle.textFormatOrange);
            this._lingqi = ObjCreate.createTextField("", 457, 24, 95, 17, this, GlobalStyle.textFormatOrange);
            this._btn = ObjCreate.createGButton(Language.getString(20024), 540, 11, 75, 25, this, "DialogOptBtn");
            this._btn.addEventListener(flash.events.MouseEvent.CLICK, this.clickBtnHander);
            ObjCreate.createBg(5, 44, 626, 1, this, ImagesConst.SplitLine);
            return;
        }

        /* internal  */onTextLinkHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            var loc1=null;
            var loc2=arg1.text;
            var loc3=Number(loc2);
            loc1 = this._taskInfo.getTargetByIndex(loc3);
            if (!loc1) 
            {
                loc1 = this._taskInfo.getTargetByIndex(0);
            }
            if (loc1) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.TaskAutoPathReq, {"target": loc1, "task": _taskInfo}));
            }
            return;
        }

        /* internal  */clickBtnHander(arg1: Object /* flash.events.Event */): void
        {
            if (this._btn.label != Language.getString(20024)) 
            {
                if (this._btn.label != Language.getString(42623)) 
                {
                    if (this._btn.label == Language.getString(42625)) 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.FairylandCommitTask, this._taskInfo));
                    }
                }
                else 
                {
                    MsgManager.showRollTipsMsg(Language.getString(42624));
                }
            }
            else 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.FairylandGetTask, this._taskInfo));
            }
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            this._taskInfo = arg1 as TaskInfo;
            this.updateView();
            return;
        }

        /* internal  */getCanGetTaskDetail(): string
        {
            var loc1=this._taskInfo.des;
            loc1 = loc1.split("<br>")[1];
            var loc2=loc1.match(new RegExp(">.*?<", "g"));
            loc1 = loc2.join("");
            loc1 = loc1.replace(new RegExp("<|>", "g"), "");
            loc1 = loc1.replace(TaskDesInfo.StepDes[1], "");
            loc1 = this.deelTaskColor(loc1);
            return loc1;
        }

        /* internal  */deelTaskColor(arg1: string): string
        {
            var loc5=null;
            var loc8=0;
            var loc9=null;
            var loc10=null;
            var loc11=null;
            var loc12=null;
            var loc13=null;
            var loc1=this._taskInfo.desTargetInfos;
            var loc2=loc1.length;
            if (loc2 < 3) 
            {
                return arg1;
            }
            --loc2;
            var loc3=ColorConfig.instance.getTaskColor("map_name").color;
            var loc4=ColorConfig.instance.getTaskColor("entity_name").color;
            var loc6;
            loc2 = (loc6 = arg1.split("、")).length;
            var loc7=0;
            while (loc7 < loc2) 
            {
                loc8 = loc7 + 1;
                loc5 = loc1[loc8];
                loc9 = loc6[loc7];
                loc10 = loc5.mapName;
                loc11 = "<u><a href=\'event:" + loc8 + "\'>" + HTMLUtil.addColor(loc10, loc3) + "</a></u>";
                loc9 = loc9.replace(loc10, loc11);
                loc12 = loc5.name;
                loc13 = "<u><a href=\'event:" + loc8 + "\'>" + HTMLUtil.addColor(loc12, loc4) + "</a></u>";
                loc9 = loc9.replace(loc12, loc13);
                loc6[loc7] = loc9;
                ++loc7;
            }
            arg1 = loc6.join("<br>");
            return arg1;
        }

        /* internal  */updateView(): void
        {
            var loc1=null;
            var loc6=null;
            var loc7=0;
            var loc8=null;
            this._taskName.htmlText = TaskConfig.instance.getTaskName(this._taskInfo.sTask.code);
            if (this._taskInfo.status != ETaskStatus._ETaskStatusCanGet) 
            {
                if (this._taskInfo.status != ETaskStatus._ETaskStatusNotCompleted) 
                {
                    loc1 = this._taskInfo.processStr;
                    loc1 = loc1.replace(new RegExp("@0|@1", "g"), "");
                    this._btn.label = Language.getString(42625);
                }
                else 
                {
                    loc1 = this._taskInfo.processStr;
                    loc1 = loc1.replace(new RegExp("@0|@1", "g"), "");
                    this._btn.label = Language.getString(42623);
                }
            }
            else 
            {
                loc1 = this.getCanGetTaskDetail();
                this._btn.label = Language.getString(20024);
            }
            this._btn.drawNow();
            this._taskContent.htmlText = loc1;
            this._taskContent.y = int((45 - 4 - this._taskContent.textHeight) * 0.5);
            this.clearRewardItems();
            var loc2=this._taskInfo.sTask.rewards;
            var loc3=loc2.length;
            var loc4=0;
            var loc5=0;
            while (loc5 < loc3) 
            {
                if ((loc7 = (loc6 = loc2[loc5]).code) != 0) 
                {
                    (loc8 = ObjectPool.getObject(BaseItemNormal)).setSize(32, 32);
                    loc8.isDragAble = false;
                    loc8.isShowLock = false;
                    loc8.itemData = new ItemData(loc7);
                    loc8.amount = loc6.num;
                    this._rewardsBox.addChild(loc8);
                    loc8.x = loc4 * 38;
                    ++loc4;
                }
                else if (loc6.type != EReward._ERewardExperience) 
                {
                    if (loc6.type == EReward._ERewardNimbus) 
                    {
                        this._lingqi.text = Language.getString(11123) + " " + loc6.num;
                    }
                }
                else 
                {
                    this._experice.text = Language.getString(11121) + " " + loc6.num;
                }
                ++loc5;
            }
            this._rewardsBox.x = 270 + (190 - loc4 * 38 - 33) / 2;
            return;
        }

        /* internal  */clearRewardItems(): void
        {
            while (this._rewardsBox.numChildren > 0) 
            {
                ObjectPool.disposeObject(this._rewardsBox.removeChildAt(0), BaseItemNormal);
            }
            return;
        }

        /* internal */ /* var */_taskInfo: TaskInfo;

        /* internal */ /* var */_taskName: Object /* flash.text.TextField */;

        /* internal */ /* var */_taskContent: Object /* flash.text.TextField */;

        /* internal */ /* var */_rewardsBox: Object /* flash.display.Sprite */;

        /* internal */ /* var */_btn: GButton;

        /* internal */ /* var */_experice: Object /* flash.text.TextField */;

        /* internal */ /* var */_lingqi: Object /* flash.text.TextField */;
    }
